{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 日期：10.26\n",
    "* 课程：python\n",
    "* 记录人：康晓棋"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "product_list = [[\"自行车\",299],\n",
    "                [\"Iphone 14 Pro\",8000],\n",
    "                [\"NFT 盲盒\",28],\n",
    "                [\"许老师的python书\",80]\n",
    "               ]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "shopping_car = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入余额:28\n",
      "\n"
     ]
    }
   ],
   "source": [
    "Alipay = input(\"请输入余额:\")\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入商品编号:3\n"
     ]
    }
   ],
   "source": [
    "uer_choice = input(\"请输入商品编号:\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-12-9b6de647c597>, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-12-9b6de647c597>\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m    if 钱够,Alipay - 商品的价格\u001b[0m\n\u001b[1;37m         ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "if 钱够,Alipay - 商品的价格\n",
    "    shopping_car.append(product_list[user_choice])\n",
    "else print(\"您的余额已不足，请更换支付方式\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "……………………"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "for i in range(4):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入余额:50000\n",
      "--------商品列表--------\n",
      "商品编号:0 ['自行车', 299]\n",
      "商品编号:1 ['Iphone 14 Pro', 8000]\n",
      "商品编号:2 ['NFT 盲盒', 28]\n",
      "商品编号:3 ['许老师的python书', 80]\n",
      "请输入商品编号:1\n",
      "您购买的商品已增加到购物车^^您的余额还有: 42000\n",
      "--------商品列表--------\n",
      "商品编号:0 ['自行车', 299]\n",
      "商品编号:1 ['Iphone 14 Pro', 8000]\n",
      "商品编号:2 ['NFT 盲盒', 28]\n",
      "商品编号:3 ['许老师的python书', 80]\n",
      "请输入商品编号:q\n",
      "您的购物车: []\n",
      "您的余额还有： 42000\n"
     ]
    }
   ],
   "source": [
    "product_list = [[\"自行车\",299],\n",
    "                [\"Iphone 14 Pro\",8000],\n",
    "                [\"NFT 盲盒\",28],\n",
    "                [\"许老师的python书\",80]\n",
    "]\n",
    "\n",
    "shopping_car = []\n",
    "\n",
    "Alipay =int( input(\"请输入余额:\"))\n",
    "while True:\n",
    "    print(\"--------商品列表--------\")\n",
    "    for i in range(4):\n",
    "        print(\"商品编号:\"+str(i),product_list[i])\n",
    "    user_chioce = input(\"请输入商品编号:\")\n",
    "    # 情景一：用户输入了商品编号：shopping\n",
    "    if user_chioce.isdigit():\n",
    "        # 判断钱够不够，商品是谁? ==> product_list[user_choice][1]\n",
    "        if Alipay >= product_list[int(user_chioce)][1]:\n",
    "            Alipay = Alipay - product_list[int(user_chioce)][1] # 买完商品剩余的钱\n",
    "            print(\"您购买的商品已增加到购物车^^您的余额还有:\",Alipay)\n",
    "        else:\n",
    "            print(\"您的余额不足，请更换支付方式^^\")\n",
    "    #情景2：用户输入“q”，退出购买\n",
    "    elif user_chioce == \"q\":\n",
    "        print(\"您的购物车:\",shopping_car)\n",
    "        print(\"您的余额还有：\",Alipay)\n",
    "        break\n",
    "    else:\n",
    "        print(\"您输入的商品不存在或输入错误，请重新尝试\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
